<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 将二进制表示减到 1 的步骤数 -->
    <script>
      //使用'0b'将字符串s标记成二进制数，然后再用BigInt转换，可以得到十进制BigInt数
      var numSteps = function (s) {
        let num = BigInt('0b' + s)
        let step = 0
        while (num !== 1n) {
          if (num % 2n === 0n) {
            num /= 2n
          } else {
            num += 1n
          }
          step++
        }
        return step
      }
      console.log(numSteps('1101'))
    </script>
  </body>
</html>
